import { Component, ElementRef, OnInit, Output, Input, ViewChild, AfterViewInit, EventEmitter } from '@angular/core';
import { Service } from '../../../server/server';
import { HttpClientModule, HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Http } from '@angular/http';
declare var $: any;

interface Response {
  result: string[];
  result_code: string;
  message: string;
  length: number;
}

@Component({
  selector: 'app-management-details',
  templateUrl: './management-details.component.html'
})
export class ManagementDetailsComponent implements OnInit {

  constructor(private server: Service, private http: HttpClient) { }

  ngOnInit() {
    this.managementeventEmit = this.server.managementeventEmit.subscribe((value: any) => {
      this.userId = value;
      this.getDetails();
      //console.log(this.userId)
    });
    //首次进入接受tree数据
    this.managementtreeidnameeventEmit = this.server.managementtreeidnameeventEmit.subscribe((value: any) => {
      this.superiorDetails = value.institutionName;
    })
  }

  //取消订阅
  public managementeventEmit: any;
  public managementtreeidnameeventEmit: any;
  ngOnDestroy() {
    if (this.managementeventEmit || this.managementtreeidnameeventEmit) {
      this.managementeventEmit.unsubscribe();
      this.managementtreeidnameeventEmit.unsubscribe();
    }
  }

  public getTabVal: any;

  @Input() superiorDetails: any;

  public userId: any;

  getDetails() {
    let url = this.server.baseUrl+'admin/pusers/getPusersInfo/' + this.userId + '';
    this.http.get<Response>(url).subscribe((data: any) => {
      //console.log(data)
      this.getTabVal = data.result;
    })
  }


}



